﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Ports;
using System.Threading;
using System.ComponentModel;
using CommonTools;
using BaseDll;
using MotionIoLib;
using Newtonsoft.Json;
namespace ModuleUnit
{
    public class ModuleBase
    {
        public string str_ModuleName = "";
        public ModuleBase(string strName)
        {
            str_ModuleName = strName;
            
        }
        public virtual bool Init()
        {
            return true;
        }

        public string strType = "";
        public object obj_Config;

        public void Io_置位并检查信号到位(string ControlIoName, bool state, string CheckIoName, bool CheckState, string InfoMsg, int timeOut = 3000)
        {
            List<string> listStationName = StationMgr.GetInstance().GetAllStationName();
            if (listStationName.Count == 0)
                throw new Exception("查找不到任何工站信息");
            bool bmanual = GlobalVariable.g_StationState == StationState.StationStateRun ? false : true;
        retry_open:
            Stationbase station = StationMgr.GetInstance().GetStation(listStationName[0]);
            IOMgr.GetInstace().WriteIoBit(ControlIoName, state);
            WaranResult waranResult = station.CheckIobyName((int)ModuleAlarm.电批吸真空, CheckIoName, CheckState, bmanual, timeOut);
            if (waranResult == WaranResult.Retry)
                goto retry_open;
        }
    }
}